//
//  VRSafetyTestingDetailViewController.m
//  VRFirefighting
//
//  Created by Veer on 2018/8/23.
//  Copyright © 2018年 Veer. All rights reserved.
//

#import "VRSafetyTestingDetailViewController.h"

#import "VRSafetyTestingModel.h"

@interface VRSafetyTestingDetailViewController ()


@property (nonatomic, strong) UIView *contentView;
@property (nonatomic, weak) UILabel *title0Lbl;
@property (nonatomic, weak) UILabel *title1Lbl;
@property (nonatomic, weak) UILabel *title2Lbl;

@property (nonatomic, strong) UIView *statusBarView;
@property (nonatomic, weak) UILabel *statusLbl;

@property (nonatomic, strong) VRSafetyTestingModel *model;

@end

@implementation VRSafetyTestingDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = ScrollViewBgColor;
    self.title = @"安全排查日志";
    
    [self setupSubView];
    [self getSafetyTestingDetail];
}

- (void)setupSubView
{
    
    UIView *contentView = [[UIView alloc] init];
    contentView.backgroundColor = MAINColor;
    [self.view addSubview:contentView];
    self.contentView = contentView;
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(NAVIGATION_BAR_HEIGHT + 20);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(130);
    }];
    
    UILabel *title0Lbl = [[UILabel alloc] init];
    title0Lbl.text = @"";
    title0Lbl.textColor = [UIColor whiteColor];
    title0Lbl.font = VRFont(16);
    [self.contentView addSubview:title0Lbl];
    self.title0Lbl = title0Lbl;
    [title0Lbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(20);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
    }];
    
    UILabel *title1Lbl = [[UILabel alloc] init];
    title1Lbl.text = @"巡查组：";
    title1Lbl.textColor = [UIColor whiteColor];
    title1Lbl.font = VRFont(16);
    [self.contentView addSubview:title1Lbl];
    self.title1Lbl = title1Lbl;
    [title1Lbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
    }];
    
    UILabel *title2Lbl = [[UILabel alloc] init];
    title2Lbl.text = @"巡查目标：";
    title2Lbl.textColor = [UIColor whiteColor];
    title2Lbl.font = VRFont(16);
    [self.contentView addSubview:title2Lbl];
    self.title2Lbl = title2Lbl;
    [title2Lbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-20);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
    }];
    
    UIView *statusBarView = [[UIView alloc] init];
    statusBarView.backgroundColor = MAINColor;
    [self.view addSubview:statusBarView];
    self.statusBarView = statusBarView;
    [statusBarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView.mas_bottom).offset(10);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(34);
    }];
    
    UILabel *signalLbl = [[UILabel alloc] init];
    signalLbl.textColor = [UIColor whiteColor];
    signalLbl.font = VRFont(16);
    [self.statusBarView addSubview:signalLbl];
    self.statusLbl = signalLbl;
    [signalLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.statusBarView);
        make.centerX.mas_equalTo(self.statusBarView);
    }];
}


#pragma mark - networking
- (void)getSafetyTestingDetail
{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"UserID"] = [VRUser shareUser].token;
    param[@"patrolRecordID"] = self.fID;
    
    weakify(self)
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [JKNetworking postWithSign:GetSafetyTestingDetail parameters:param success:^(NSDictionary *responseObject) {
        
        strongify(self)
        NSLog(@"responseObject:%@", responseObject);
        NSInteger code = [responseObject[@"state"] integerValue];
        NSString *msg = responseObject[@"message"];
        
        if (code == 0) {
            
            VRSafetyTestingModel *model = [VRSafetyTestingModel mj_objectWithKeyValues:responseObject[@"data"]];
            dispatch_async(dispatch_get_main_queue(), ^{
                self.model = model;
                [hud hideAnimated:YES];
            });
        }else if(msg.length > 0){
            dispatch_async(dispatch_get_main_queue(), ^{

                [SVProgressHUD showErrorWithStatus:msg];
                [hud hideAnimated:YES];
            });
        }
    } error:^(NSError * _Nonnull error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [SVProgressHUD showErrorWithStatus:@"未知错误"];
            [hud hideAnimated:YES];
        });
    }];
}

#pragma mark - setter && getter
- (void)setModel:(VRSafetyTestingModel *)model
{
    _model = model;
    
    self.title0Lbl.text = [NSString stringWithFormat:@"%@", model.fDisposeTime ? model.fDisposeTime : @""];
    self.title1Lbl.text = [NSString stringWithFormat:@"巡更组：%@", model.fShiftsName ? model.fShiftsName : @""];
    self.title2Lbl.text = [NSString stringWithFormat:@"巡更目标：%@", model.fTaskName ? model.fTaskName : @""];;
    
    
    if ([model.fState isEqualToString:@"error"]) {
        self.statusLbl.text = [NSString stringWithFormat:@"巡更状态：未巡更"];
    }else{
        self.statusLbl.text = [NSString stringWithFormat:@"巡更状态：已巡更"];
    }
    
    //
    //    self.numberLbl.text = [NSString stringWithFormat:@"%03zd", model.number];
    //    self.titleLbl.text = model.fFacilityModelID;
    //
    //    NSDictionary *typeDict = @{@(0) : @{@"name": @"正常", @"color": RGB(78, 173, 57), @"icon": @"i_data_success"}, @(1) : @{@"name": @"报警", @"color": RGB(238, 11, 25), @"icon": @"i_data_error"}, @(3) : @{@"name": @"故障", @"color": RGB(251, 86, 31), @"icon": @"i_data_error"}};
    //    self.signalLbl.backgroundColor = typeDict[@(model.fState)][@"color"];
    //    self.signalLbl.text = typeDict[@(model.fState)][@"name"];
    //
    //    self.statusLbl.text = typeDict[@(model.fState)][@"name"];
    //    self.statusLbl.textColor = typeDict[@(model.fState)][@"color"];
    //
    //    self.statusImgView.image = [UIImage imageNamed:typeDict[@(model.fState)][@"icon"]];
    //
    //    if (model.fFacilitySwitch == 1) {
    //        self.contentView.backgroundColor = RGB(140, 140, 140);
    //        self.titleLbl.textColor = [UIColor whiteColor];
    //        self.signalLbl.hidden = YES;
    //
    //        self.statusLbl.text = @"关闭";
    //        self.statusLbl.textColor = [UIColor whiteColor];
    //        self.statusImgView.hidden = YES;
    //    }else{
    //        self.contentView.backgroundColor = RGB(255, 255, 255);
    //        self.titleLbl.textColor = RGB(51, 51, 51);
    //        self.signalLbl.hidden = NO;
    //        self.statusImgView.hidden = NO;
    //    }
}


@end
